<?php

namespace App\Http\Controllers\Talent;

use App\Http\Controllers\BaseController;
use App\Http\Services\Rank;
use App\Http\Services\RankList;
use App\Models\Post;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class PostController extends BaseController
{
    public function index()
    {
//        $redis = new Rank('brandLike-2024-07');
//
//         DB::table('user_like_brands')
//                 ->selectRaw('brand_id,count(id) as like_count')
//                 ->whereYear('like_time','2024')
//                 ->whereMonth('like_time','07')
//                 ->where('status',1)
//                 ->groupBy('brand_id')
//                 ->orderBy('brand_id')
//                 ->chunk(100,function ($brands) use ($redis){
//                     foreach ($brands as $brand){
//                         $redis->updateScore($brand->brand_id,$brand->like_count);
//                     }
//                 });
//
//
//
//        dd($redis->getRank(13),$redis->getList(5));


//        $rankList = new RankList($redis,'brandLike','brand');
//        $rankList->flush();
//        $rankList->updateScore(1,100,json_encode([
//            'brand_id' => 1,
//            'name' => '豪华品牌',
//            'photo' => '图片'
//        ]));
//        $rankList->updateScore(2,110,json_encode([
//            'brand_id' => 2,
//            'name' => '豪华品牌2',
//            'photo' => '图片2'
//        ]));
//
//        $result = $rankList->getList(-1,true);
//
//        dd($result);

        $posts = Post::query()->where('status',1)->get();

        return $this->success($posts);
    }
}
